# ResponseIndividual Lab 2
We will be working with a database from the Star Wars universe. We need to first install the package :
install.packages(“starwarsdb”)
Please make note that this is a different kind of way we can enter data into R. We have entered what is called a “database” which is different from a text file, a dataframe, a tibble, etc.
We will need to use the “dplyr” library to access this data, so install it if it is not already installed.
install.packages(“dplyr”)
# Responsedplyr should now be installed, but may not be loaded. You can load the library by checking it off in the packages tab, or you can enter the following :
library(dplyr)
# ResponseWe are now ready to create a dataframe using a combination of “dplyr” and the “as.data.frame” command. This is similar to the “as.tibble” command used above. Let’s store the information in the variable starwars_DF :
starwars_DF <- as.data.frame(dplyr::starwars)
# ResponseCheck the variable to make sure it is a dataframe.
class(starwars_DF)
# ResponseNow we are ready to start answering questions.
- Use two different methods for finding the number of rows in your data frame. What does this represent?
# Response- Use two different methods for finding the number of columns in your data frame. What does this represent?
# Response- Determine the dimensions of the dataframe using the dim command. What does this tell us?
# Response- What command can we use to list off the variable names in the dataframe? Carry out that command.
# Response- We want to pull out the “height” variable. Carry out two different commands that will pull out this information and save it to a new variable called SW_height. How many values are listed? Does this raise any concerns?
# Response- Do all of the observations have a value for height? If not, how many are missing and who are they missing from?
# Response- Print out the heights from smallest to largest. Also save the sorted list to a new variable called SW_height_sorted_1
# Response- Use the sort help file to see how to sort the values from largest to smallest. Then print out the heights from largest to smallest and save new sorted list to SW_height_sorted_2
# Response- Find two ways to find the maximum values of the height. Save this value to the variable SW_max_height.
# Response- Find two ways to find the minimum values of the height. Save this value to the variable SW_max_height.
# Response- Turn this dataframe into a tibble named SW_tibble.
# Response